home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 10-InfoSystems / samba / samba-gen.frm.z / samba-gen.frm
Encoding:
Text File  |  2002-06-12  |  8.3 KB  |  319 lines

  1. #!/usr/bin/perl5
  2. #
  3. # samba-gen.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: samba-gen.frm,v 1.8 1998/02/11 23:21:12 jrw Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $help_page = "samba-gen-help.html";
  26.  
  27. $js_edit =
  28. "$js_standard;
  29. $js_error_box;
  30. $js_help
  31. $js_filename;
  32. $js_hostname;
  33. function checkForm(form) {
  34.     if (!testFileChars(form.workgroup.value)) {
  35.         errorBox(form.workgroup, \"The workgoup name cannot contain \"
  36.             + \"metacharacters.\");
  37.         return (false);
  38.     }
  39.     if (!testHostname(form.wins_server, form.wins_server.value, 
  40.         \"wins server\", 1)) return (false);
  41.     print = form.print_command.value;
  42.     ind = print.indexOf(\" \", 0);
  43.     if (ind == -1) {
  44.         if (!testFilename(form.print_command, \"print command\"))
  45.             return (false);
  46.     } else {
  47.         path = print.substring(0, ind);
  48.         if (!myTestFilename(form.print_command, path, \"print commant\")) return (false);
  49.         if (!myTestFileChars(form.print_command.value)) {
  50.             errorBox(form.print_command, \"The print command cannot contain \"
  51.                 + \"meta characters.\");
  52.             return (false);
  53.         }
  54.     }
  55.     return (true);
  56. }
  57. function myTestFilename(Ctrl, word, what) {
  58.         if (word == \"\") {
  59.                 errorBox (Ctrl, \"The \" + what + \" is required.\");
  60.                 return (false);
  61.         }
  62.         if (!myTestFileChars(word)) {
  63.                 errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain \"
  64.                         + illegal + \" characters.\");
  65.                 return (false);
  66.         }
  67.         for(i = 0; i < word.length; i++) {
  68.                 if (word.charAt(i) == ' ') {
  69.                         errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain spaces.\");
  70.                         return (false);
  71.                 }
  72.         }
  73.         if (word.charAt(0) != '/') {
  74.                 errorBox (Ctrl, \"The \" + what + \" must be fully qualified.\");
  75.                 return (false);
  76.         }
  77.         return (true);
  78. }
  79. function myTestFileChars(word) {
  80.         metaChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\";
  81.         for(j = 0; j < metaChars.length; j++) {
  82.                 illegal = metaChars.charAt(j);
  83.                 if (word.indexOf (illegal, 0) != -1) return (false);
  84.         } return (true);
  85. }";
  86.  
  87. $myname = "samba-gen.cgi";
  88. $title = "SAMBA Configuration";
  89.  
  90. open(IN, "/usr/bsd/hostname |");
  91. $host = <IN>;
  92. close(IN);
  93. chop($host);
  94.  
  95. $defaults = "   server string = $host, samba %v\n"
  96.     . "   guest = nobody\n"
  97.     . "   wins support = yes\n"
  98.     . "   load printers = yes\n"
  99.     . "   printing = sysv\n"
  100.     . "   preserve case = yes\n"
  101.     . "   short preserve case = yes\n\n";
  102.  
  103.  
  104. if ( -e "/usr/freeware/lib/samba/smbd" ) {
  105.     $smbd = "/usr/freeware/lib/samba/smbd";
  106.     $conf_dir = "/usr/freeware/lib/samba";
  107. } elsif ( -e "/usr/local/samba/bin/smbd" ) {
  108.     $smbd = "/usr/local/samba/bin/smbd";
  109.     $conf_dir = "/usr/local/samba/lib";
  110. } elsif ( -e "/usr/samba/bin/smbd" ) {
  111.     $smbd = "/usr/samba/bin/smbd";
  112.     $conf_dir = "/usr/samba/lib";
  113. } else {
  114.     print "Content-type: text/html\n\n";
  115.     &title_block($title);
  116.     &header_block($title);
  117.     print "<i>SAMBA software not installed.  Please install subsystem "
  118.         . "</i><b>fw_samba</b><i> from the <a "
  119.         . "href=\"http://www.sgi.com/TasteOfDT/public/freeware.html\" "
  120.         . "target=\"FREEWARE\">SGI freeware CD</a> or download the "
  121.         . "software from the Internet.</i>\n\n";
  122.     exit 0;
  123. }
  124. $conf = "$conf_dir/smb.conf";
  125. $dummy = "$conf_dir/smb.conf.tmp";
  126.  
  127. &get_fields2;
  128.  
  129. &get_vals;
  130.  
  131. if (%fld) {
  132.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  133.     $help =~ s/cgi$/hlp/;
  134.     exec $help if ($fld{'help'} eq "Help");
  135.  
  136.     if ($fld{'ok'}) { 
  137.         &doEdit; 
  138.         &get_vals; 
  139.         &editAccount; 
  140.     }
  141. } else { &editAccount; }
  142. exit 0;
  143.  
  144. sub get_fields2 {
  145.   my $buffer, $name, $value, $pair, @pairs;
  146.  
  147.   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  148.  
  149.   @pairs = split(/&/, $buffer);
  150.  
  151.   foreach $pair (@pairs) {
  152.     ($name, $value) = split(/=/, $pair);
  153.     $value =~ tr/+\t/  /;
  154.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  155.  
  156.     $name = "xaster" if ($name eq "*");
  157.     $name =~ s/\+/ /g;
  158.  
  159.     $fld{$name} = $value;
  160.   }
  161. }
  162.  
  163. sub doEdit {
  164.     $added = 0;
  165.     open(IN, "< $conf");
  166.     open(OUT, "> $dummy");
  167.     while(<IN>) {
  168.         if ($_ =~ /\[global\]/) {
  169.             while(<IN>) {
  170.                 if ($_ =~ /\[.*\]/) { last; }
  171.             }
  172.  
  173.             print OUT "[global]\n";
  174.             &add_global;
  175.             $added = 1;
  176.     
  177.             print OUT $_;
  178.         } else { print OUT $_; }
  179.     }
  180.     close(IN);
  181.     close(OUT);
  182.     rename($dummy, $conf);
  183.  
  184.     if ($added == 0) {
  185.         open(OUT, "> $conf");
  186.         print OUT "[global]\n";
  187.         &add_global;
  188.         close(OUT);
  189.     }
  190.  
  191.     if ($fld{'enable'} eq "Yes") {
  192.         system("/etc/chkconfig", "samba", "on");
  193.         unless (fork) {
  194.             unless (fork) {
  195.                 sleep 1 until getppid == 1;
  196.                 system("/etc/init.d/samba stop > /dev/null 2>&1");
  197.                 system("/etc/init.d/samba start > /dev/null 2>&1");
  198.                 exit 0;
  199.             }
  200.             exit 0;
  201.         }
  202.         wait;
  203.     } else {
  204.         if (!fork) {
  205.             system("/etc/chkconfig", "samba", "off");
  206.             system("/etc/init.d/samba stop > /dev/null");
  207.             exit 0;
  208.         }
  209.     }
  210. }    
  211.  
  212. sub add_global {    
  213.     if ($fld{'browse'} eq "Yes") {
  214.         print OUT "   preferred master = yes\n",
  215.             "   os level = 50\n";
  216.     }
  217.     if ($fld{'domain'} eq "Yes") {
  218.         print OUT "   domain master = yes\n";
  219.     }
  220.     if ($fld{'workgroup'}) {
  221.         print OUT "   workgroup = $fld{'workgroup'}\n";
  222.     }
  223.     if ($fld{'wins_server'}) {
  224.         print OUT "   wins server = $fld{'wins_server'}\n";
  225.     }
  226.     if ($fld{'print_command'}) {
  227.         print OUT "   print command = $fld{'print_command'}\n";
  228.     }
  229.     print OUT $defaults;
  230. }
  231.     
  232. sub get_vals {
  233.     $val{'browse'} = "No";
  234.     $val{'domain'} = "No";
  235.  
  236.     open(IN, "< $conf");
  237.     
  238.     $read_lines = 0;
  239.     while(<IN>) {
  240.         if ($_ =~ /\[global\]/) { $read_lines = 1; next; }
  241.         elsif ($_ =~ /\[.*\]/) { $read_lines = 0; next; }
  242.         next if $read_lines == 0;
  243.         next if substr($_,0,1) eq ";";
  244.  
  245.         if ($_ =~ /(.*)=(.*[^\s].*)/) {
  246.             $parm = $1;
  247.             $value = $2;
  248.  
  249.             $parm =~ /^\s*([^\s].*[^\s])\s*$/; $parm = $1;
  250.             $value =~ /^\s*([^\s].*)$/; $value = $1;
  251.  
  252.             if (($parm eq "preferred master" && $value eq "yes") 
  253.                 || ($parm eq "os level" && $value > 34)) {
  254.                 $val{'browse'} = "Yes";
  255.             }
  256.  
  257.             if ($parm eq "domain master" && $value eq "yes") {
  258.                 $val{'domain'} = "Yes";
  259.             }
  260.  
  261.             if ($parm eq "wins server") {
  262.                 $val{"wins_server"} = $value;
  263.             }
  264.  
  265.             if ($parm eq "workgroup") {
  266.                 $val{$parm} = $value;
  267.             }
  268.  
  269.             if ($parm eq "print command") {
  270.                 $val{"print_command"} = $value;
  271.             }
  272.         }
  273.     }
  274.  
  275.     $chk = system ("/etc/chkconfig", "samba");
  276.     if ($chk) { $val{'enable'} = "No"; }
  277.     else { $val{'enable'} = "Yes"; }
  278. }    
  279.  
  280. sub editAccount {
  281.     print "Content-type: text/html\n\n";
  282.     
  283.         &js_title_block($title,$js_edit);
  284.  
  285.         &header_block("SAMBA Configuration");
  286.  
  287.     print "$message<br>";
  288.         
  289.     print "<form name=StandardForm action=$myname method=post "
  290.         . "onSubmit=\"return runSubmit()\">";
  291.  
  292.     print "<center><table width=450>\n";
  293.  
  294.     print "<tr><th align=left>Enable Samba?\n",
  295.         "<td><b>", &radio("enable", $val{'enable'}, "Yes", "No"), "</b></td></tr>\n";
  296.  
  297.     print "<tr><th align=left>Name of workgroup:\n",
  298.         "<td>", &text("workgroup", $val{'workgroup'}, 20), "</td></tr>\n";
  299.  
  300.     print "<tr><th align=left>Set this server to be a browse master?\n",
  301.         "<td><b>", &radio("browse", $val{'browse'}, "Yes", "No"), "</b></td></tr>\n";
  302.  
  303.     print "<tr><th align=left>Set this server to be a domain master?\n",
  304.         "<td><b>", &radio("domain", $val{'domain'}, "Yes", "No"), "</b></td></tr>\n";
  305.  
  306.     print "<tr><th align=left>Name of network wins server:\n",
  307.         "<td>", &text("wins_server", $val{'wins_server'}, 20), "</td></tr>\n";
  308.  
  309.     print "<tr><th align=left>Print command:\n",
  310.         "<td>", &text("print_command", $val{'print_command'}, 20), "</td></tr>\n";
  311.         
  312.     print "</table></center><br><br>\n";
  313.  
  314.     print &js_buttons('ok','Ok','onClick="markOK()"',
  315.             'onClick="markOther()"',
  316.             "onClick=\"do_help('$help_page'); return (false)\"");
  317.         print "</form></body></html>";
  318. }
  319.